package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"novels/models"
)

type NovelController struct {
	beego.Controller
}

func (c *NovelController) Add() {
	title := c.GetString("title")
	author := c.GetString("author")
	commit := c.GetString("commit")
	novel := models.Novels{
		Title:  title,
		Author: author,
		Commit: commit,
	}
	err := models.DB.Create(&novel).Error
	if err != nil {
		c.Data["json"] = map[string]interface{}{
			"code": 0,
			"msg":  "添加成功",
		}
	} else {
		c.Data["json"] = map[string]interface{}{
			"code": 200,
			"msg":  "添加失败",
		}
	}
}

func (c *NovelController) Del() {

}

type JsonRpa struct {
	Code     int         `json:"code"`
	Msg      string      `json:"msg"`
	Data     interface{} `json:"data"`
	Page     int         `json:"page"`
	size     int         `json:"size"`
	PageData int         `json:"page-data"`
	Count    int64       `json:"count"`
}

//func (c *NovelController) List() {
//	page, _ := c.GetInt("page", 1)
//	size := 5
//
//}
